#include "fxcc/imgui/Editor.h"
#include "fxcc/core/graph/common/AnimationController.h"

using namespace fxcc::imgui;
using namespace fxcc::graph::common;

template<>
bool Editor::NodeEdit<AnimationController>(const std::string& l, AnimationController& e)
{
    bool flag{ 0 };

    ImNodes::BeginNodeEditor();


    ImNodes::EndNodeEditor();
    return flag;
};

template<>
 bool Editor::Edit<AnimationController>(const std::string& l, AnimationController& e)
{
    int index = 8;

    if (TreeNode("state", e.m_ImguiFlag, index++))
    {
        EditInst<bool>("m_TransitionWorking", e.m_TransitionWorking);
        SelectFromMap<int, AnimationNode>("m_StartAnimId", e.m_StartAnimId, e.m_AnimationNodes);
        SelectFromMap<int, AnimationNode>("m_AnimId", e.m_AnimId, e.m_AnimationNodes);
        SelectFromMap<int, AnimTransition>("m_TransitionId", e.m_TransitionId, e.m_AnimTransitions);
        
        TreePop();
    }
    if (TreeNode("Params", e.m_ImguiFlag, index++))
    {
        EditInst<Params>("Params", e.m_Params);
        TreePop();
    }
    if (TreeNode("anim nodes", e.m_ImguiFlag, index++))
    {
        for (auto& [key, value] : e.m_AnimationNodes)
        {
            if (TreeNode(std::to_string(key), value.m_TreeNode))
            {

                TreePop();
            }
        }
        TreePop();
    }

    if (TreeNode("transitions", e.m_ImguiFlag, index++))
    {
        for (auto& [key2, value2] : e.m_AnimTransitions)
        {
            if (TreeNode(std::to_string(key2), value2.m_TreeNode))
            {
                SelectFromMap<int, AnimationNode>("m_LeftId", value2.m_LeftId, e.m_AnimationNodes);
                SelectFromMap<int, AnimationNode>("m_RightId", value2.m_RightId, e.m_AnimationNodes);
                EditInst<float>("m_BlendTime", value2.m_BlendTime);

                ImGui::DragFloat("m_LeftAxis", &value2.m_LeftAxis, 0.01f, 0.f, 0.99f);
                ImGui::DragFloat("m_RightAxis", &value2.m_RightAxis, 0.01f, 0.f,0.99f);
                ImGui::DragFloat("m_TransitionAxis", &value2.m_TransitionAxis, 0.01f, 0.f, 0.99f);                
                TreePop();
            }
        }
        TreePop();
    }
    if (ImGui::Button("+ node"))
    {
        e.m_AnimationNodes[fxcc::Base::generateIDFromTime()] = {};
    }
    ImGui::SameLine();
    if (ImGui::Button("+ transition"))
    {
        e.m_AnimTransitions[fxcc::Base::generateIDFromTime()] = { };
    }


    return false;
}